'''
中国农业银行账户管理系统
'''
import random
# user_count = random.randint(10000000,99999999)
# user_type = 0
# user_name = ''
# user_password = 0
# user_address = ''
# user_balance = 0
# user_bank = ''
print('''
*********************************
*      中国农业银行账户管理系统      *    
*********************************
*             选项               *
*            1.开户              *
*            2.存钱              *
*            3.取钱              *
*            4.转账              *
*            5.查询              *
*            6.Bye              *
*********************************
''')

bank ={
         'user1' :{
                'user_count':'12345678',
                'user_type': '001',
                'user_name' :'Lucy',
                'user_password' : '123456',
                'user_address' : '中国河南郑州枫林路001',
                'user_balance' :1000,
                'user_bank' : '中国农业银行的昌平沙河支行'
                }
}
print(bank)
def open():   # 开户函数
    user = {}
    count= input('请输入您的账号：')
    user['user_count'] = count
    type= input('请输入您的账户类型：')
    user['user_type'] = type
    name= input('请输入您的用户名：')
    user['user_name'] = name
    password= input('请输入您的密码：')
    user['user_password'] = password
    address= input('请输入您的地址：')
    user['user_address'] =address
    balance= input('请输入您的账户余额：')
    user['user_balance'] = balance
    bank_name= input('请输入您的开户行： ')
    user['user_bank'] = bank_name
    print(user)
    for user_info in bank.values():
        if user_info['user_count']==count:
               return 2  # 2：用户已存在
        elif len(bank) >= 100:
                return  3  # 3：用户库已满
        else:
              bank[f'user{len(bank)+1}'] = user
              return 1  # 1：成功

def save(save_count, save_pw, save_money):# 存钱
    for user_info in bank.values():
        if user_info['user_count'] == save_count:
            balance = float(user_info['user_balance'])
            balance = balance + save_money
            print('存储成功，账户余额为：{}'.format(balance))
            user_info['user_balance'] = balance
            return True
    else:
        print('账号不存在')


def take (take_count,take_pw,take_money): # 取钱
    for user_info in bank.values() :
      if user_info['user_count'] == take_count:
        if  user_info['user_password'] == take_pw :
            balance = float(user_info['user_balance'])
            if take_money <= balance:
                balance= balance - take_money
                print('成功取出，账户余额为：{}'.format(balance))
                return  0
            else:
                print('钱不够')
                return  3
        else:
            print('密码错误')
            return 2
      else:
        print('账号不存在')
        return 1

def transfer(transfer_out_count,transfer_in_count,transfer_out_pw,transfer_money):  # 转账
  out_user = None
  in_user = None
  for user_info in bank.values():
    if user_info['user_count'] == transfer_out_count:
        out_user = user_info
    if user_info['user_count'] == transfer_in_count:
        in_user = user_info
        if transfer_out_pw == out_user['user_password']:
            now_transfer = float(input('你要转多少钱'))
            if transfer_money >= now_transfer:
                out_money = float(out_user['user_balance'])
                out_money= out_money - now_transfer
                in_money = float(in_user['user_balance'])
                in_money = in_money + now_transfer
                return None
            else:
                print('金额不足')
                return  3
        else:
            print('密码不对')
            return 2
    else:
        print('账户不存在')
        return 1

def refer(refer_count,refer_pw):  # 查询账户
  for user_info in bank.values():
    if user_info['user_count'] == refer_count:
        if refer_pw == user_info['user_password']:
            print(user_info['user_count'])
        else:
            print('密码错误')
    else:
        print('用户不存在')

if __name__ == '__main__':
    select = input('您要办理什么业务？请输入对应数字：')
    if select == '1':
        print(open())
    elif select == '2':
        save_count = input('请输入用户账号')
        save_pw = input('请输入账号密码')
        save_money = float(input('请输入存储金额'))
        print(save(save_count, save_pw, save_money))
    elif  select == '3' :
        take_count = input('请输入用户账号')
        take_pw = input('请输入账号密码')
        take_money = float(input('请输入取出金额'))
        print(take(take_count, take_pw, take_money))
    elif select =='4'  :
        transfer_out_count = input('请输入转出用户账号')
        transfer_in_count = input('请输入转入用户账号')
        transfer_out_pw = input('请输入账号密码')
        transfer_money = float(input('请输入转账金额'))
        print(transfer(transfer_out_count, transfer_in_count, transfer_out_pw, transfer_money))
    elif select == '5' :
        refer_count = input('请输入用户账号')
        refer_pw = input('请输入账号密码')
        print(refer(refer_count,refer_pw))
    elif select == '6' :
        print('再见')
    else:
        print('输入错误')

